import { useEffect, useState } from "react";


export default function useLocalStorage(key: string, initialValue: string) {
  const [value, setValue] = useState<string | null>(initialValue)

  useEffect(() => {
    const storedValue = window.localStorage.getItem(key)
    if (key) {
      setValue(storedValue)
    }
  }, [key])

  useEffect(() => {
    window.localStorage.setItem(key, value as string)
  }, [key, value])

  return [value, setValue]
}